from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from tortoise.contrib.fastapi import register_tortoise
from settings import TORTOISE_ORM
from apps.app01_url import app1
from apps.app02_params import app2
from apps.app03_request_response import app3
from apps.app04_request_params import app4
from apps.app05_request_body import app5
from apps.app06_form_data import app6
from apps.app07_request_object import app7
from apps.app08_jinjia2 import app8
from apps.app09_orm import app9
from apps.app10_orm_crud import app10


app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")

# 数据库相关配置
register_tortoise(
    app=app,
    config = TORTOISE_ORM,
    # generate_schemas=True,  # 如果数据库为空，则自动生成对应的表单，生产环境不要开
    # add_exception_handlers=True  # 添加 ORM 异常处理，生产环境不要开，会泄露调试信息

)

# 在app上挂载路由
app.include_router(app1,tags=['01 路径参数演示'])
app.include_router(app2,tags=['02 装饰器函数演示'])
app.include_router(app3,prefix='/user', tags=['03 请求与响应演示'] )
app.include_router(app4,tags=['04 查询参数'])
app.include_router(app5,tags=['05 请求体'])
app.include_router(app6,tags=['06 表单数据'])

app.include_router(app7,tags=['07 request对象'])
app.include_router(app8,tags=['08 请求静态资源'])
app.include_router(app9,tags=['09 ORM'])
app.include_router(app10,tags=['10 orm增删改查'])



if __name__ == '__main__':
    import uvicorn
    uvicorn.run('main:app',port=8000,host='127.0.0.1',reload=True)


